//
//  CABaseController.m
//  cascade-realm
//
//  Created by QSC on 15/5/24.
//

#import "CABaseController.h"
#import "CAHomeController.h"
#import "CAVideoController.h"
#import "CAForumController.h"
#import "CAMineController.h"
@interface CABaseController ()

@end

@implementation CABaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = Hex(0xFCFFF6);
    self.navigationController.navigationBar.hidden = YES;
    
    [self setUpNav];
}

- (void)setUpNav{
    
    UIView * navView = [UIView new];
    self.navView = navView;
    [self.view addSubview:navView];
    [navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(kNavigationBarHeight);
    }];
    
    
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:Img(@"back") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(navView).offset(KNavigationStatusHeight * 0.5);
        make.left.equalTo(navView).offset(20);
    }];
    self.backBtn = backBtn;
    

    [navView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backBtn);
        make.centerX.equalTo(navView);
    }];
 
}

- (void)setNavTitle:(NSString *)navTitle{
    _navTitle = navTitle;
    self.titleLabel.text = navTitle;
}


- (UILabel *)titleLabel{
    if (_titleLabel == nil) {
        _titleLabel = [UILabel LabelWithFont:Font(18) color:Hex(0x202020) text:@""];
    }
    return _titleLabel;
}


- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    if ([self isKindOfClass:[CAHomeController class]]) {
        [Http PostLogWithPage:@"tab-home"];
    }else
    
    if ([self isKindOfClass:[CAVideoController class]]) {
        [Http PostLogWithPage:@"tab-video"];
    }else
    
    if ([self isKindOfClass:[CAForumController class]]) {
        [Http PostLogWithPage:@"tab-forum"];
    }else
    
    if ([self isKindOfClass:[CAMineController class]]) {
        [Http PostLogWithPage:@"tab-mine"];
    }
}
@end
